package gatperdut.chato.core.item;

import gatperdut.chato.constants.CSConstantsInventory;
import gatperdut.chato.model.Chato.Constant.WearLoc;
import gatperdut.chato.model.Chato.Item.Wear;

public class WearController {

    private final Wear wear;

    public WearController( Wear wear ) {
        this.wear = wear;
    }

    public boolean hasSeveralWearLocs() {
        return getWear().getWearLocs().size() > 1;
    }

    public boolean canBeWornIn( WearLoc wearLoc ) {
        return getWear().getWearLocs().contains( wearLoc );
    }

    public String listWearLocations() {
        StringBuilder sb = new StringBuilder( "" );

        int n = getWear().getWearLocs().size();
        int current = 0;
        boolean firstListed = false;
        for ( WearLoc wearLoc : getWear().getWearLocs() ) {
            current++;
            if ( !firstListed ) {
                firstListed = true;
            }
            else {
                if ( current == n ) {
                    sb.append( " and " );
                }
                else {
                    sb.append( ", " );
                }
            }
            sb.append( CSConstantsInventory.getWearLocName( wearLoc ) );
        }
        sb.append( "." );

        return sb.toString();
    }

    public WearLoc getFirstWearLoc() {
        return getWear().getWearLocs().get( 0 );
    }

    public Wear getWear() {
        return wear;
    }

}
